PAB = {}

// Override standard functions 
	local oldHookAdd = hook.Add
	local oldHookRemove = hook.Remove
	
// Set up local variables
	local Hooks = {}
	local Modules = {}

// Hook Functions 

	local function GenerateString()
	
		local str = ""
		local num = 0
		local rand = math.random(3,19)
		
		for i = 1, rand do
		
			num = math.random(65, 116)
				if num > 90 and num < 97 then num = num + 6 end
			str = str .. string.char(num)
			
		end
			
		return str
		
	end
	
	local function AddHook( call, func )
	
		local name = GenerateString()
		
		Hooks[name] = call
		
		oldHookAdd( call, name, func )
		
	end
	
	function hook.Remove( call, name )
	
		for k,v in pairs( Hooks ) do
		
			if v.name == name and v.call == call then return else

				oldHookRemove( call, name )
				
			end
			
		end
		
	end

// PAB Register and reloading functions 
	
	function PAB.Print( msg )
	
		print( "[PAB] " .. msg )
		
	end
	
	function PAB.Register( module )
		
		if not module then PAB.Print( "Failure to register module " .. module.Name ) return end
		
		for k,v in pairs(module.Hooks) do
		
			PAB.Print( "Loading module " .. module.Name .. "!  Hook -- " .. v )
			AddHook( v, k )
			
		end
		
	end
	
	local function Unload()
	
		for k,v in pairs( Hooks ) do
			
			PAB.Print( "Unloading hook " .. v )
			oldHookRemove( v, k )
			Hooks[k] = nil
			
		end
		
	end
	
	local function Reload()
	
		Unload()
		
		for k,v in pairs( Modules ) do
		
			PAB.Print( "Executing " ..  v )
			include(v)
			Modules[v] = nil
			
		end
		
	end

// Command Add 
	concommand.Add( "PAB_Reload", Reload )
	concommand.Add( "PAB_Unload", Unload )